<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录界面</title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script src="/qcbycoursehelper/resours/js/cookie.js"></script>

<link rel="stylesheet" type="text/css" href="/qcbycoursehelper/resours/css/index.css">
</head>
<body class="bg">
    <div class="box">
         <h3>Please Enter Your Info</h3>   
         <form class="myForm1">
              <input type="radio" name="flag" value="1" checked="checked"/>管理员
              <input type="radio" name="flag" value="0" checked="checked"/>学生
              <input type="radio" name="flag" value="2" checked="checked"/>老师
         </form>   
         <form class="myForm">
              <h4>Your Account</h4>
              <input type="text" id="userName"/>
              <h4>Your Password</h4>
              <input type="text" id="password"/>
              <input class="AAA" type="button" value="Finish" onclick="get()"/>
         </form>
     
    </div>
</body>
<script>
function get(){
	// ajax ---》 利用ajax进行数据提交  // ++ http协议
	var url = "http://localhost:8080/qcbycoursehelper/LoginServlet"; 
	var data = {
			"userName":$("#userName").val(),
			"password":$("#password").val(),
			"type":$('input[name="flag"]:checked').val()
	}
	$.ajax({
        type:"post",//指定提交的类型，get对应doget(),post对应dopost()
        url: url,   // 地址
        data:data,//data代表key -value类型的数据  
        dataType:'JSON', //定义数据的类型
        success: function (value)//success、error代表是否返回成功
        {
        	console.log(value);
        	if(value.message=="老师"){
        		window.location.href="http://localhost:8080/qcbycoursehelper/classMessage.html";
        	}else if(value.message=="管理员"){
        		window.location.href="http://localhost:8080/qcbycoursehelper/Admin.html";
        	}else if(value.message=="学生"){
        		window.location.href="http://localhost:8080/qcbycoursehelper/student.html";
        	}
        },
        error:function (XMLHttpRequest, textStatus, errorThrown) { 
            alert(typeof(errorThrown));
        }
     });
}
</script>
</html>